﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using ThreeByte.ActiveDeck.AddIn.Controls.Wizard.Themes;
using System.ComponentModel;
using ThreeByte.ActiveDeck.Config;

namespace ThreeByte.ActiveDeck.AddIn.Controls.Wizard.Pages
{
    /// <summary>
    /// Interaction logic for ChooseThemePage.xaml
    /// </summary>
    public partial class ChooseThemePage : Page, INotifyPropertyChanged
    {
        private readonly CoreConfig Config;

        public ChooseThemePage() {
            InitializeComponent();

            Config = WizardMainFrame.ActiveConfig;

            this.DataContext = this;
            if(Themes.Count > CurrentThemeIndex) {
                CurrentPreviewTheme = Themes[CurrentThemeIndex];
            }
            UpdateButtons();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private List<WizardTheme> Themes = WizardTheme.Themes.ToList();
        private int CurrentThemeIndex = 0;

        public WizardTheme _currentPreviewTheme;
        public WizardTheme CurrentPreviewTheme {
            get {
                return _currentPreviewTheme;
            }
            set {
                _currentPreviewTheme = value;
                NotifyPropertyChanged("CurrentPreviewTheme");
            }
        }


        private void CannotExecute(object sender, CanExecuteRoutedEventArgs e) {
            e.CanExecute = false;
            e.Handled = true;
        }

        private void HelpExecuted(object sender, ExecutedRoutedEventArgs e) {

        }


        private void NextPageExecuted(object sender, ExecutedRoutedEventArgs e) {
            NavigationService navService = this.NavigationService;
            if(navService != null) {
                navService.Navigate(new CreateContentPage());
            }
        }

        private void PrevThemeButton_Click(object sender, RoutedEventArgs e) {
            if(CurrentThemeIndex > 0) {
                CurrentThemeIndex = CurrentThemeIndex - 1;
                CurrentPreviewTheme = Themes[CurrentThemeIndex];
            }
            UpdateButtons();
        }

        private void NextThemeButton_Click(object sender, RoutedEventArgs e) {
            if(CurrentThemeIndex < Themes.Count - 1) {
                CurrentThemeIndex = CurrentThemeIndex + 1;
                CurrentPreviewTheme = Themes[CurrentThemeIndex];
            }
            UpdateButtons();
        }

        private void UpdateButtons() {
            NextSlideButton.IsEnabled = (CurrentThemeIndex < Themes.Count - 1);
            PrevSlideButton.IsEnabled = (CurrentThemeIndex > 0);
        }

        private void ChooseTheme_Click(object sender, RoutedEventArgs e) {
            Button btn = (Button)sender;
            WizardTheme theme = (WizardTheme)(btn.Tag);
            if(theme == null) {
                return;
            }

            Config.Theme = theme;

            //Go to the next page with this selection
            NavigationService navService = this.NavigationService;
            if(navService != null) {
                navService.Navigate(new CreateContentPage());
            }
        }

       
    }
}
